package code.google.com.analyticsbot;

import java.lang.reflect.Field;
import javax.jdo.annotations.Persistent;

public class Helpers
{
	private Helpers()
	{
	}

	/**
     * Iterates through the object and makes any persistent annotated objects that are serialized = "true"
     * dirty using <code>javax.jdo.JDOHelper.makeDirty</code>.
     * @param <T>
     * @param instance
     */
    public static <T> void makeSerializedDirty(T instance)
    {
    	// see http://groups.google.com/group/google-appengine-java/msg/d86bc7718267952b?dmode=source
    	for(Field field : instance.getClass().getDeclaredFields())
    	{
    		Persistent persistent = field.getAnnotation(Persistent.class);
    		if((persistent != null) && Boolean.valueOf(persistent.serialized()))
    		{
    			javax.jdo.JDOHelper.makeDirty(instance, field.getName());
    		}
    	}
    }
}
